package Thread.ThreadPoolClose;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Shutdown {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService pool1=new ThreadPoolExecutor(3,6,10,
                TimeUnit.SECONDS,new LinkedBlockingQueue<>(3),new ThreadPoolExecutor.AbortPolicy());
        for (int i = 0; i <6 ; i++) {
            pool1.submit(()->{
                while (true){
                    System.out.println(Thread.currentThread().getName()+"正在运行~~");
                    Thread.sleep(1000);
                }
            });
        }
        //主线程休眠6秒后关闭线程池
        Thread.sleep(6000);
//        pool1.shutdown();
        pool1.shutdownNow();
        if (pool1.isShutdown()){
            System.out.println("线程池已经关闭~");
        }
    }
}
